home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / oper_sys / kerberos / pc / krb_libw.lha / Lib / WINKRB / NETREAD.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-23  |  1.1 KB  |  54 lines

  1. /*
  2.  * $Source: /mit/kerberos/src/lib/krb/RCS/netread.c,v $
  3.  * $Author: jtkohl $
  4.  *
  5.  * Copyright 1987, 1988 by the Massachusetts Institute of Technology.
  6.  *
  7.  * For copying and distribution information, please see the file
  8.  * <mit-copyright.h>.
  9.  */
  10.  
  11. #include <mit_copy.h>
  12. #include <conf.h>
  13. #ifdef WINDOWS
  14. #include <windows.h>
  15. #include <sys/socket.h>
  16. #endif
  17.  
  18. /*
  19.  * krb_net_read() reads from the file descriptor "fd" to the buffer
  20.  * "buf", until either 1) "len" bytes have been read or 2) cannot
  21.  * read anymore from "fd".  It returns the number of bytes read
  22.  * or a read() error.  (The calling interface is identical to
  23.  * read(2).)
  24.  *
  25.  * XXX must not use non-blocking I/O
  26.  */
  27.  
  28. int
  29. krb_net_read(fd, buf, len)
  30. int fd;
  31. register char *buf;
  32. register int len;
  33. {
  34.     int cc, len2 = 0;
  35.  
  36.     do {
  37. #ifdef IBMPC
  38.     cc=soread(fd,buf,len);
  39. #else
  40.     cc = read(fd, buf, len);
  41. #endif
  42.     if (cc < 0)
  43.         return(cc);         /* errno is already set */
  44.     else if (cc == 0) {
  45.         return(len2);
  46.     } else {
  47.         buf += cc;
  48.         len2 += cc;
  49.         len -= cc;
  50.     }
  51.     } while (len > 0);
  52.     return(len2);
  53. }
  54.